﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * 目标标本：4.0.30319.239
 * 
 * 最后修改：2011/11/11 18:17:36
 * ************************************************************/
namespace Mozlite.Common
{
    using System;
    using System.Linq;
    using System.Text;
    using System.Collections.Generic;
    using Mozlite.Common.Configuration;

    /// <summary>
    /// 用户中心权限。
    /// </summary>
    public class UCenterPermission : PermissionBase
    {
        /// <summary>
        /// 初始化类<see cref="T:Mozlite.Common.UCenterPermission"/>。
        /// </summary>
        public UCenterPermission()
        {
            this.SchemaID = new Guid("5008F785-6740-4F52-AF3F-EAD705412927");
            this.SettingsID = SiteSettings.Current.SettingsID;
            this.AllowableExtensions = "jpg,png,gif,txt,zip,rar";
            this.MaxSingleFileLength = Globals.KBytes * 100;
            this.MaxDiskSize = Globals.MBytes * 10;
            this.CommentLength = 256;
        }

        /// <summary>
        /// 允许上传的文件扩展名。
        /// </summary>
        [Merger(MergerMode.Merger, ",")]
        public string AllowableExtensions { get; set; }

        /// <summary>
        /// 获取或设置单个文件最大大小。
        /// </summary>
        [Merger(MergerMode.Greater)]
        public long MaxSingleFileLength { get; set; }

        /// <summary>
        /// 获取或设置磁盘大小。
        /// </summary>
        [Merger(MergerMode.Greater)]
        public long MaxDiskSize { get; set; }

        /// <summary>
        /// 允许上传文件。
        /// </summary>
        public bool? AllowUpload { get; set; }

        /// <summary>
        /// 允许上传图片文件。
        /// </summary>
        public bool? AllowUploadImage { get; set; }

        /// <summary>
        /// 允许上传Flash文件。
        /// </summary>
        public bool? AllowUploadFlash { get; set; }

        /// <summary>
        /// 允许上传媒体文件。
        /// </summary>
        public bool? AllowUploadMedia { get; set; }

        /// <summary>
        /// 允许文件浏览。
        /// </summary>
        public bool? AllowFileBrowser { get; set; }

        /// <summary>
        /// 判断上传文件是否被允许。
        /// </summary>
        /// <param name="extension">文件扩展名。</param>
        /// <returns>返回判断结果。</returns>
        public bool IsFileAllowed(string extension)
        {
            if (AllowableExtensions == null || AllowableExtensions == "*")
                return true;
            return (this.AllowableExtensions + ",").IndexOf(extension + ",") != -1;
        }

        /// <summary>
        /// 允许编辑评论。
        /// </summary>
        public bool? AllowComments { get; set; }

        /// <summary>
        /// 评论长度。
        /// </summary>
        public int CommentLength { get; set; }
    }
}